package com.jingmi.common.Validated;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class EnumConstrainValiator implements ConstraintValidator<EnumValidate,Integer> {
    private Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(EnumValidate constraintAnnotation) {

        //提交的是value的值
        int[] values = constraintAnnotation.values();
        for (int value : values) {

            set.add(value);
        }

    }
    //返回的是表单提交的isshow值
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println("Valiator value==>"+set);
        System.out.println(" Valiator integer==>"+integer);

        return set.contains(integer);
    }
}
